package com.njit.WeStudy.dao;

import com.njit.WeStudy.dataobject.Group;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

public interface GroupMapper {
    @Delete({
        "delete from group",
        "where group_id = #{groupId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer groupId);

    @Insert({
        "insert into group (group_name, ",
        "group_type, master_id, ",
        "preview_image_url, create_time, ",
        "delete_time, is_deleted)",
        "values (#{groupId,jdbcType=INTEGER}, #{groupName,jdbcType=VARCHAR}, ",
        "#{groupType,jdbcType=VARCHAR}, #{masterId,jdbcType=INTEGER}, ",
        "#{previewImageUrl,jdbcType=VARCHAR}, now()",
        "#{deleteTime,jdbcType=TIMESTAMP}, #{isDeleted,jdbcType=BIT})"
    })
    int insert(Group record);

    @Select({
        "select",
        "group_id, group_name, group_type, master_id, preview_image_url, create_time, ",
        "delete_time, is_deleted",
        "from group",
        "where group_id = #{groupId,jdbcType=INTEGER}"
    })
    @Results(id = "resultMap",value = {
        @Result(column="group_id", property="groupId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="group_name", property="groupName", jdbcType=JdbcType.VARCHAR),
        @Result(column="group_type", property="groupType", jdbcType=JdbcType.VARCHAR),
        @Result(column="master_id", property="masterId", jdbcType=JdbcType.INTEGER),
        @Result(column="preview_image_url", property="previewImageUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="delete_time", property="deleteTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="is_deleted", property="isDeleted", jdbcType=JdbcType.BIT)
    })
    Group selectByPrimaryKey(Integer groupId);

    @Select({
        "select",
        "group_id, group_name, group_type, master_id, preview_image_url, create_time, ",
        "delete_time, is_deleted",
        "from group"
    })
    @ResultMap("resultMap")
    List<Group> selectAll();

    @Update({
        "update group",
        "set group_name = #{groupName,jdbcType=VARCHAR},",
          "group_type = #{groupType,jdbcType=VARCHAR},",
          "master_id = #{masterId,jdbcType=INTEGER},",
          "preview_image_url = #{previewImageUrl,jdbcType=VARCHAR},",
          "delete_time = #{deleteTime,jdbcType=TIMESTAMP},",
          "is_deleted = #{isDeleted,jdbcType=BIT}",
        "where group_id = #{groupId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Group record);
}